/**
 * @file main.cc
 * @author your name (you@domain.com)
 * @brief 主线程
 * @version 0.1
 * @date 2022-09-17
 * 
 * @copyright Copyright (c) 2022
 * 
 */

#include "imageProcess.h"
#include "face_detect.h"
#include "save_img.h"
int target_368 = 0;
char *yolov5_model_path = NULL; 
char *pose_model_path = NULL; 
double __get_us(struct timeval t) { return (t.tv_sec * 1000000 + t.tv_usec); }
/*-------------------------------------------
                Main
-------------------------------------------*/
int main(int argc, char *argv[4])
{
	if (argc != 4) {
		cout << "Usage of this exec: ./程序名 需要检测的jpg文件夹路径  目标检测模型  人体关键点检测模型" << endl;
		return -1;
	}
    char *dirName = argv[1];        //传入目标文件夹
    yolov5_model_path = argv[2];    //指向yolov5模型路径
    pose_model_path = argv[3];      //指向pose模型路径
    int cpus = 0;
    struct timeval start_time, stop_time;
    gettimeofday(&start_time, NULL);
	cpus = sysconf(_SC_NPROCESSORS_CONF);               //cortex -A7处理器核心数是4
	printf("This system has %d processor(s).\n", cpus);

    //主线程中启动1号：图像保存线程 和 2号：人脸检测线程
    array<thread, 2> threads;
	threads = {thread(save_img,1), thread(face_detector,2)};

    cout << "This is main thread" <<endl;

    //遍历目标文件夹并放队列
    int ret;
    ret = glob_dir_And_push_img_queue(dirName);
    if(ret == -1){
        cout << "遍历文件夹为空"<< endl;
        return -1;
    }
    gettimeofday(&stop_time, NULL);
    printf(" 主线程预处理图像的时间： %f ms\n",(__get_us(stop_time) - __get_us(start_time)) / 1000);
    
    
    for (int i = 0; i < 2; i++)     threads[i].join();
    return 0;
}


